var normalizeCache = function(caching) {
		if (caching == null) {
	        return {
	        	"xml":false,
	        	"xsl":true,
	        	"result":false,
	        	"ajax":false
	        };
	    } else if (caching === true) {
	    	return {
	        	"xml":true,
	        	"xsl":true,
	        	"result":true,
	        	"ajax":true
	        };
	    }
		return caching;
	};

var initXML = function (func) {
		return {
			readyState: 4,
			getResponseHeader:function(header) {
				return null;
			}
	    };
	};
	
var tryExtractFromCache = function(xml,caching,innerCache,target) {
		if (caching) {
			if (!checkObjectType(xml)) {
				var value = innerCache.getElement(xml);
				if (value) {
					debug(xml + " - already cached! Element:"+target.attr("id"));
					return value;
				}
			}	
		}
		return xml;
	};
	
var setIf = function(expression,trueValue,falseValue) {
		if (expression) {
			return trueValue;
		}
		return falseValue;
	};

var setFromCache = function(object,param) {
		object.responseXML = param;
		return object;
	};
	
var getXMLRepresentation = function(object){
		return object.responseXML;
	};
	
var checkByCache = function(cache,key) {
		if (cache) {
			return false;
		}
		return key;
	};
var checkByExpires = function(expires,key) {
		if (expires){
			if (expires > new Date()) {
				return false;
			} else {
				return true;
			}
		}
		return key;
	};
	
var setFromFile = function(object,param,func){
		object = $.ajax({dataType: "xml", url: param, cache:false});
		object.onreadystatechange = func;
		return object;
	};

var isSettedXMLDocument = function(node) {
		if (node.XMLDocument==null || node.XMLDocument.xml=='') {
			return true;
		}
		return false;
	};
	
var trySetToFixCache = function(key,xhr,uin,cache,postfix){
		if (key && xhr.readyState == completeValue) {
			cache.setElement(uin+postfix,xhr.responseXML);
		}
	};
	
var truncateXHR = function(xhr,uin,dnsCache,postfix) {
		var cache = xhr.getResponseHeader("Cache-control");
		var pragma = xhr.getResponseHeader("Pragma");
		var expires = xhr.getResponseHeader("Expires");
		return {
			responseXML:dnsCache.getElement(uin+postfix),
			getResponseHeader:function(header) {
				switch(header) {
					case "Cache-control":return cache; break;
					case "Pragma":return pragma; break;
					case "Expires":return expires; break;
					case "":return null; break;
					default:return null;
				}
			}
		};
	};